var fs = require('fs');
// console.log(process.argv[2]);
var num;
if (!fs.existsSync('./frequency.txt')) {
  fs.writeFileSync('./frequency.txt', 7);
}
if (!fs.existsSync('./nums.txt')) {
  fs.writeFileSync('./nums.txt', num = Math.floor(Math.random() * 100 + 1));
}




var str = fs.readFileSync('./nums.txt', 'utf-8');
// console.log(str);



if (str=='') {
    num = Math.floor(Math.random() * 100 + 1);
    fs.writeFileSync('./nums.txt', num);
}



var inputNum = process.argv[2];
// console.log(inputNum);

 

  
  cishu=fs.readFileSync('./frequency.txt', 'utf-8');

  var  frequency=cishu 

       frequency--;
       fs.writeFileSync('./frequency.txt', frequency);

 
        if (inputNum == str) {
          console.log("猜对了");
          num = Math.floor(Math.random() * 100 + 1);
          fs.writeFileSync('./nums.txt', num);
          fs.writeFileSync('./frequency.txt', 7);
          
        } else if (inputNum > str) {
          console.log("你是猪吗？ 大了 还剩"+frequency +"次");
       
        } else {
            console.log("你是猪吗？ 小了 还剩"+frequency +"次");
           
        }
        
        if (frequency == 0) {
          console.log("没机会了结束游戏 请重新开始猜");
          num = Math.floor(Math.random() * 100 + 1);
          fs.writeFileSync('./nums.txt', num);
          fs.writeFileSync('./frequency.txt', 7);
        }












